<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 和为 K 的最少斐波那契数字数目 -->
    <script>
      var findMinFibonacciNumbers = function (k) {
        let arr = [1, 1]
        while (arr[arr.length - 1] < k) {
          arr.push(arr[arr.length - 1] + arr[arr.length - 2])
        }
        let res = 0,
          cur = k
        while (cur > 0) {
          let l = 1,
            r = arr.length - 1
          while (l < r) {
            let m = Math.ceil((l + r) / 2)
            if (arr[m] <= cur) l = m
            else r = m - 1
          }
          res += 1
          cur -= arr[l]
        }
        return res
      }
      console.log(findMinFibonacciNumbers(7))
    </script>
  </body>
</html>
